//
//  UIView+UIViewCategory.m
//  QuTouTiao
//
//  Created by 杨杨子 on 2018/5/26.
//  Copyright © 2018年 杨杨子. All rights reserved.
//

#import "UIView+UIViewCategory.h"
#import <objc/runtime.h>
static char tapBlockKey;

@interface UIView()

@end
@implementation UIView (UIViewCategory)
-(void)setX:(CGFloat)x{
    CGRect frame = self.frame;
    frame.origin.x = x;
    self.frame = frame;
}
-(CGFloat)x{
    return self.frame.origin.x;
}
//
-(void)setY:(CGFloat)y{
    
}
-(CGFloat)y{
    return self.frame.origin.y;
}
//
-(void)setWidth:(CGFloat)width{
    
}
-(CGFloat)width{
    return self.bounds.size.width;
}
//
-(void)setHeight:(CGFloat)height{
    
}
-(CGFloat)height{
    return self.bounds.size.height;
}
//
-(void)setCenterX:(CGFloat)centerX{
    
}
-(CGFloat)centerX{
    return self.centerX;
}
//
-(void)setCenterY:(CGFloat)centerY{
    
}
-(CGFloat)centerY{
    return self.centerY;
}
//
-(void)setSize:(CGSize)size{
    
}
-(CGSize)size{
    return self.frame.size;
}
-(void)setCornerRadius:(double)cornerRadius AndBorderColor:(UIColor *)color AndBorderWidth:(double)width{
    self.layer.cornerRadius = cornerRadius;
    self.layer.masksToBounds = YES;
    self.layer.borderWidth = width;
    self.layer.borderColor = color.CGColor;
}
-(void)viewTapBlock:(void(^)(void))block
{
    objc_setAssociatedObject(self, &tapBlockKey, block, OBJC_ASSOCIATION_COPY_NONATOMIC);
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGr:)];
    [self addGestureRecognizer:tap];
}
-(void)tapGr:(UITapGestureRecognizer *)gr{
   ActionBlock block = objc_getAssociatedObject(self, &tapBlockKey);
    if (block) {
        block();
    }
}


@end
